package UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ServerDemo1 {

    public static void main(String[] args) throws Exception {
        System.out.println("服务端启动=======>");
        DatagramSocket socket=new DatagramSocket(9999);

        byte[] buffer=new byte[1024*64];
        DatagramPacket packet=new DatagramPacket(buffer,buffer.length);


        while(true){
            socket.receive(packet);
            int length=packet.getLength();
            String rs=new String(buffer,0,length);
            String ip = packet.getAddress().toString();
            System.out.println(ip);
            int port = packet.getPort();
            System.out.println(port);
            System.out.println("=====>"+rs);
        }

//        socket.close();
    }
}
